package com.hexun.es.util;

/**
 * @description:结果对象
 * @author:yrw
 * @date 2018/11/19
 */
public class Result {

    //返回结果
    private Boolean code;
    //返回消息
    private String message;
    //返回数据
    private Object data;

    public Boolean getCode() {
        return code;
    }

    public void setCode(Boolean code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Result(Boolean code,String message){
        this.code=code;
        this.message=message;
    }

    public Result(Boolean code,String message,Object data){
        this.code=code;
        this.message=message;
        this.data=data;
    }


    //构造一个返回成功的结果
    public static Result getSuccess(){
        return new Result(true,null);
    }

    //构造一个返回成功的结果
    public static Result getSuccess(Object data){
        return new Result(true,null,data);
    }

    //构造一个返回失败的结果
    public static Result getFail(){
        return new Result(false,null);
    }

    //构造一个返回失败的结果
    public static Result getFail(String message){
        return new Result(false,message);
    }

    //判断返回是否成功
    public boolean Success(){
        return this.code;
    }

    //判断返回是否失败
    public boolean Fail(){
        return !this.code;
    }
}
